import {defineConfig} from 'vite'
import vue from '@vitejs/plugin-vue'
import {fileURLToPath, URL} from 'node:url'

// https://vite.dev/config/
export default defineConfig({
    plugins: [vue()],
    resolve: {
        alias: {
            '@': fileURLToPath(new URL('./src', import.meta.url))
        }
    },
    server: {
        host: '0.0.0.0',
        proxy: {
            '/api': {
                target: 'https://opencj.cn',
                changeOrigin: true,
                // rewrite: (path) => path.replace(/^\/api/, ''),
                // configure: (proxy, options) => {
                //   proxy.on('proxyReq', (proxyReq, req, res) => {
                //     console.log(`[代理请求] ${req.method} ${req.url} -> ${options.target}${proxyReq.path}`);
                //   });
                //   proxy.on('proxyRes', (proxyRes, req, res) => {
                //     console.log(`[代理响应] ${req.method} ${req.url} <- ${proxyRes.statusCode}`);
                //   });
                //   proxy.on('error', (err, req, res) => {
                //     console.error(`[代理错误] ${req.method} ${req.url}`, err);
                //   });
                // }
            }
        }
    }
})
